#ifndef SERIAL_H
#define SERIAL_H

#include <stdio.h>	/*标准输入输出定义*/
#include <stdlib.h> /*标准函数库定义*/
#include <stdint.h>
#include <unistd.h> /*Unix 标准函数定义*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>	 /*文件控制定义*/
#include <termios.h> /*PPSIX 终端控制定义*/
#include <errno.h>	 /*错误号定义*/

#define buffer_length 100
#define max_info 50

using namespace std;
class serialPort
{
private:
	int fd;
	struct termios Opt;
	int speed_arr[15] = {
		B115200,
		B38400,
		B19200,
		B9600,
		B4800,
		B2400,
		B1200,
		B300,
		B38400,
		B19200,
		B9600,
		B4800,
		B2400,
		B1200,
		B300,
	};
	int name_arr[15] = {
		115200,
		8400,
		19200,
		9600,
		4800,
		2400,
		1200,
		300,
		38400,
		19200,
		9600,
		4800,
		2400,
		1200,
		300,
	};

public:
	serialPort();
	bool OpenPort(const char *dev);
	int setup(int speed, int flow_ctrl, int databits, int stopbits, int parity);
	void set_speed(int speed);
	int set_Parity(int databits, int stopbits, int parity);
	int readBuffer(char *buffer, int size);
	int writeBuffer(char *buffer, int size);
	void getRes(char *cmd, char *result);
	void ReadFilename(char *filenamearry);
	void ClosePort();
	void read_record(char &num, char startime[max_info][20], char endtime[max_info][20]);
};

#endif // !SERIAL_H